<template>
  <div>
    <!--ref的基本类型：-->
    数值：{{ sum }}
    <button @click="changeNum">增加</button>
  </div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'

const sum = ref(0)

const changeNum = () => {
  sum.value++
}

const stopWatch = watch(sum, (newVal, oldVal) => {
  console.log('watch触发了：', newVal, oldVal)
  if (newVal > 10) {
    stopWatch() // 结束watch！
  }
})

console.log('stopWatch:', stopWatch)
</script>
<style scoped></style>
